package com.example.demo.Mapper;

import com.example.demo.Model.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface CommentsMapper {

    // 插入 并查询id 赋给传入的对象
    @Insert("INSERT INTO comments(time, message, username) VALUES(#{time}, #{message}, #{username})")
    @SelectKey(statement = "SELECT seq id FROM sqlite_sequence WHERE (name = 'comments')", before = false, keyProperty = "id", resultType = int.class)
    int insert(CommentsModel model);

    // 查询全部
    @Select("SELECT * FROM comments")
    List<CommentsModel> selectAll();

    // 更新 value
    @Update("UPDATE comments SET value=#{value} WHERE id=#{id}")
    int updateValue(CommentsModel model);

    // 根据 ID 删除
    @Delete("DELETE FROM comments WHERE id=#{id}")
    int delete(Integer id);

}